<template>
  <div class="login-container">
    <div class="first-img">
      <img src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u3.png" alt="">
    </div>
    <div class="second-img">
      <img src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u4.png" alt="">
    </div>
    <div class="third-img">
      <img src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u5.png" alt="">
    </div>
    <div class="four-img">
      <img src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u25.png" alt="">
    </div>

    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
      <div class="title-container">
        <div>
          <img src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u24.png" alt="">
        </div>
        <h3 class="title">电商后台管理</h3>
      </div>

      <el-form-item prop="username">
        <div class="svg-container">
          <!-- <svg-icon icon-class="user" /> -->
          <img src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u13.png" alt="">
        </div>
        <el-input
          ref="username"
          v-model="loginForm.username"
          placeholder="账号"
          name="username"
          type="text"
          tabindex="1"
          auto-complete="off"
        />
      </el-form-item>

      <el-form-item prop="password">
        <span class="svg-container">
          <img style="width:20px" src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u17.png" alt="">
        </span>
        <el-input
          :key="passwordType"
          ref="password"
          v-model="loginForm.password"
          :type="passwordType"
          placeholder="密码"
          name="password"
          tabindex="2"
          auto-complete="off"
          @keyup.enter.native="handleLogin"
        />
        <span class="show-pwd" @click="showPwd">
          <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
        </span>
      </el-form-item>
      <el-form-item prop="password" style="position:relative">
        <span class="svg-container">
          <!-- <svg-icon icon-class="password" /> -->
          <img src="https://img.axureshop.com/7a/4a/a8/7a4aa826e79b40d086fba67fb100e0f9/images/0登陆页/u21.png" alt="">
        </span>
        <el-input
          ref="code"
          v-model="loginForm.code"
          placeholder="验证码"
          name="code"
          auto-complete="off"
          @keyup.enter.native="handleLogin"
        />
        <div class="box_3">
          5&nbsp;7&nbsp;6&nbsp;9
        </div>
      </el-form-item>

      <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">登录</el-button>
    </el-form>
  </div>
</template>
<script>
import { validUsername } from '@/utils/validate'

export default {
  name: 'Login',
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!validUsername(value)) {
        callback(new Error('Please enter the correct user name'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error('The password can not be less than 6 digits'))
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        username: '',
        password: '',
        code: ''
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleLogin() {
      this.$router.push('/')
    }
  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg:#283443;
$light_gray:#fff;
$cursor: #fff;

// @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
//   .login-container .el-input input {
//     color: $cursor;
//   }
// }

/* reset element-ui css */
.login-container {
  .el-form-item__content{
    line-height: 30px;
    position: relative;
    font-size: 14px;
  }
  .el-form-item {
    border: 1px solid #ccc;
    width: 100%;
    border-radius: 5px;
    .el-input{
      height: 30px;
      width: 85%;
    }
  }
}
</style>

<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-image: linear-gradient(#3fccfd, #996cfb);
  position: relative;
  overflow: hidden;
  .first-img{
    position: absolute;
    left: 30px;
    top: 30px;
    opacity: 0.3;
  }
  .second-img{
    position: absolute;
    right: 150px;
    top: -200px;
  }
  .third-img{
    position: absolute;
    left: -300px;
    bottom: -100px;
    opacity: 0.9;
  }
  .four-img{
    position: absolute;
    left: 400px;
    top: 250px;
  }
  .login-form{
    position: absolute;
    top: 250px;
    left: 900px;
    width: 450px;
    height: 450px;
    background-color: #fff;
    border-radius: 20px;
    padding: 30px 50px;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    width: 35px;
    display: inline-block;
    img{
      vertical-align: middle;
    }
  }

  .title-container {
    display: flex;
    justify-content: center;
    align-items: center;
    .title {
      color: #438dee;
      margin-left: 10px;
      letter-spacing: 1px;
      font-family: "楷体 Bold", "楷体 Regular", 楷体;
      font-weight: 700;
      font-style: normal;
      font-size: 32px;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
 ::v-deep .el-input__inner{
    border: none;
    background-color: #FFF;
    background-image: none;
    border-radius: 4px;
    /* border: 1px solid #DCDFE6; */
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: 0;
    padding: 0 15px;
    -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    width: 100%;
  }
  .box_3{
    position: absolute;
    right: 0;
    top: 0;
    height: 43px;
    width: 115px;
    background-color: #cccccc;
    border-radius: 0 5px 5px 0;
    margin-top: -1px;
    text-align: center;
    line-height: 43px;
    color: #ff7733;
    font-size: 20px;
    font-weight: 700;
  }
</style>
